package com.example.test.dao;

import com.example.test.dto.DirectorMovie;
import com.example.test.entities.Director;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DirectorRepository extends JpaRepository<Director,Long> {
    @Override
    List<Director> findAll();

    @Query(nativeQuery = true,value = "SELECT d.name, d.opus , COUNT(md.director_id) AS moviesDirectorCount " +
            "FROM director AS d LEFT JOIN movies_director AS md ON md.driector_id = d.driector_id " +
            " GROUP BY d.name, d.opus ORDER BY 3 desc;")
        List<DirectorMovie> directorMovies();
}
